<?php
/**
 * Created by PhpStorm.
 * User: qixiuxiu
 * Date: 2017/4/4
 * Time: 11:45
 */
require_once __DIR__ . '/../vendor/autoload.php';//包容这个文件，可以允许类被自动加载

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$request = Request::createFromGlobals();//createFromGlobals()方法基于当前PHP全局变量创建了一个Request对象。
//$response = new Response();//使用response

//$map用相对应的PHP脚本路径（paths）关联了URL路径。
$map = array(
//    '/index' => __DIR__ . '/../src/pages/index.php',
//    '/bye' => __DIR__ . '/../src/pages/bye.php',
    '/bye' => 'index',
    '/bye' => 'bye',
);

$path = $request->getPathInfo();//返回请求的路径部分
if (isset($map[$path])){
    ob_start();//打开缓冲区
    //extract — 从数组中将变量导入到当前的符号表
    extract($request->query->all(),EXTR_SKIP);
    include sprintf(__DIR__.'/../src/pages/%s.php',$map[$path]);
    //$response->setContent(ob_get_clean());//获取当前缓冲区内容到response的setContent并删除当前的输出缓冲区
    $reponse = new Response(ob_get_clean());
}else{
    //$response->setStatusCode(404);
    //$response->setContent('Not Found');
    $reponse = new Response('Not Found',404);
}

$response->send();